package com.itheima.huikebackend.controller;

import com.itheima.huikebackend.common.R;
import com.itheima.huikebackend.common.Result;
import com.itheima.huikebackend.dto.CluePoolDTO;
import com.itheima.huikebackend.entity.ClueTrackRecord;
import com.itheima.huikebackend.entity.TbClue;
import com.itheima.huikebackend.service.TbClueService;
import com.itheima.huikebackend.vo.ClueSelectIdVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/clues")
public class TbClueController {

    private final TbClueService tbClueService;

    /**
     * 列表
     *
     * @param tbClue 线索页面dto
     * @return {@link R}<{@link Map}<{@link String},{@link Object}>>
     */
    @GetMapping("/clue/list")
    public R<Map<String,Object>> list(TbClue tbClue){
        log.info("参数：{}",tbClue);
       Map map =  tbClueService.list(tbClue);
       return R.success(map);
    }

    /**
     * 创建
     *
     * @param tbClue 结核病线索创造dto
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/clue")
    public Result<?> create (@RequestBody TbClue tbClue){
        tbClueService.create(tbClue);
        return Result.success();
    }

    /**
     * 查询
     *
     * @param id id
     * @return {@link Result}<{@link TbClue}>
     */
    @GetMapping("/clue/{id}")
    public Result<ClueSelectIdVO> query(@PathVariable Long id){
        ClueSelectIdVO clueSelectIdVO = tbClueService.query(id);
        return Result.success(clueSelectIdVO);
    }

    /**
     * 查询列表
     *
     * @return {@link Result}<{@link List}>
     */
    @GetMapping("/record/list")
    public Result<List<ClueTrackRecord>> queryList(Long clueId){
       List<ClueTrackRecord>  clueTrackRecord = tbClueService.queryList(clueId);
        log.info("参数{}",clueTrackRecord);
        return Result.success(clueTrackRecord);
    }

    /**
     * 池列表
     *
     * @return {@link R}<{@link Map}<{@link String} ,{@link Object}>>
     */
    @GetMapping("/clue/pool")
    public R<Map<String ,Object>> poolList(CluePoolDTO cluePoolDTO){
       Map map = tbClueService.poolList(cluePoolDTO);
        return R.success(map);
    }
}
